package Example2;

import sun.reflect.generics.tree.Tree;

import java.util.Comparator;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * 区分Comparable和Comparator两个接口。
 */
public class Main {
    public static void main(String[] args) {
        TreeMap<Integer,Student> stuMap=new TreeMap<>();
        TreeSet<Student> stuSet=new TreeSet<>();
        stuMap.put(1,new Student("阿帆",24));
        stuMap.put(2,new Student("小名",27));
        stuMap.put(3,new Student("赵云",17));
        stuMap.put(4,new Student("曹操",26));
        stuMap.put(5,new Student("狄仁杰",48));
        stuMap.put(6,new Student("范伟",53));
        stuMap.put(7,new Student("刘柱",80));
        stuMap.forEach((key,values)->{
            System.out.println(key+" : "+values);
        });

        // System.out.println("=============================");
        // stuSet.addAll(stuMap.values());
        // stuSet.forEach((student)->{
        //     System.out.println(student);
        // });




    }
}

//Comparator是自定义专用比较器时需要实现的接口。当我们希望采用外部的比较器，或者给其它方法传入一个比较器参数时就需要实现这个接口。
class MyStudentComparator implements Comparator<Student>{

    @Override
    public int compare(Student s1, Student s2) {
        System.out.println(s1);
        System.out.println(s2);
        System.out.println("------------------------------");
        return s1.getScore()-s2.getScore();
    }

}
